//
//  ViewController.m
//  網易
//
//  Created by 赵天宇 on 16/8/15.
//  Copyright © 2016年 赵天宇. All rights reserved.
//

#import "ViewController.h"
#import "MainViewController.h"
#define WIDTH  self.view.frame.size.width
@interface ViewController ()<UIScrollViewDelegate>
{
//    滚动视图
    UIScrollView *myScorllV;
//    图片数组
    NSArray *arrPhoto;
//    滚动视图上的点
    UIPageControl *pageC;
//     跳转按钮
    UIButton *goBtn;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self scorllVinit];
    [self getImage];
    [self pageCInit];
    [self initGoBtn];
    // Do any additional setup after loading the view, typically from a nib.
}
//将图片添加到滚动视图上
-(void)getImage{
    arrPhoto = @[@"屏幕快照 2016-09-06 下午3.24.43.png",@"201512279405108200.png",@"screen322x572.jpg",@"20151011102338105.jpg"];
//    循环添加图片
    for (int i=0; i<arrPhoto.count; i++) {
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH*i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageV.image=[UIImage imageNamed:arrPhoto[i]];
        [myScorllV addSubview:imageV];
    }
//    设置滚动视图的内容大小
    myScorllV.contentSize=CGSizeMake(arrPhoto.count*WIDTH, self.view.frame.size.height);
}
//初始化滚动视图
-(void)scorllVinit{
    myScorllV = [[UIScrollView alloc]initWithFrame:self.view.frame];
    myScorllV.pagingEnabled=YES;
    myScorllV.bounces=NO;
    myScorllV.delegate=self;
    myScorllV.showsHorizontalScrollIndicator=NO;
    [self.view addSubview:myScorllV];
}
//滚动视图将要滚动(协议方法)，
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    pageC.currentPage=myScorllV.contentOffset.x/self.view.frame.size.width;
}
//pageC的初始化
-(void)pageCInit{
    pageC = [[UIPageControl alloc]initWithFrame:CGRectMake(150, 600, 100, 40)];
    pageC.numberOfPages=arrPhoto.count;
    pageC.currentPageIndicatorTintColor=[UIColor yellowColor];
    pageC.pageIndicatorTintColor=[UIColor redColor];
    [self.view addSubview:pageC];
//    方法
    [pageC addTarget:self action:@selector(click) forControlEvents:UIControlEventValueChanged];
    
}
//pageC的方法
-(void)click{
//    点控制视图的切换
    myScorllV.contentOffset=CGPointMake(pageC.currentPage*self.view.frame.size.width, 0);
}
//初始化进入按钮
-(void)initGoBtn{
    goBtn = [UIButton buttonWithType:0];
    goBtn.frame=CGRectMake(3*self.view.frame.size.width+380, self.view.frame.size.height/2, 20, 20);
    goBtn.layer.masksToBounds=YES;
    goBtn.layer.cornerRadius=10;
    [goBtn setBackgroundImage:[UIImage imageNamed:@"night_see_more_cell_arrow@2x.png"] forState:0];
    goBtn.backgroundColor = [UIColor clearColor];
    [goBtn setTitleColor:[UIColor lightGrayColor] forState:0];
    [goBtn addTarget:self action:@selector(click_2) forControlEvents:UIControlEventTouchUpInside];
    [myScorllV addSubview:goBtn];
}
-(void)click_2{
    MainViewController *vv = [[MainViewController alloc]init];
    CATransition *tran = [CATransition animation];
    tran.duration=1.5;
    //    tran.type=@"cameraIrisHollowOpen";
    //    pageCurl            向上翻一页
    //    pageUnCurl          向下翻一页
    //    rippleEffect        滴水效果
    //    suckEffect          收缩效果，如一块布被抽走
    //    cube                立方体效果
    //    oglFlip             上下翻转效果
    tran.type=@"rippleEffect";
    tran.subtype=kCAAlignmentLeft;
    [self.view.window.layer addAnimation:tran forKey:nil];
    [self presentViewController:vv animated:YES completion:nil];
     }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
